package com.ttg.utils.connection;

//~--- non-JDK imports --------------------------------------------------------

import com.ttg.utils.Assert;

import java.nio.charset.Charset;
import java.util.Map;
import java.util.regex.Pattern;

//~--- JDK imports ------------------------------------------------------------

//~--- classes ----------------------------------------------------------------

/**
 * Class HttpRequest
 * Description
 * Create 2015-09-11 09:14:28
 * @author Ardy    
 */
public class HttpRequest {

    /** 
     * Field METHOD_GET
     * Description 
     */
    public static final String METHOD_GET = "GET";

    /** 
     * Field METHOD_POST
     * Description 
     */
    public static final String METHOD_POST = "POST";

    /** 
     * Field DEFAULT_CHARSET
     * Description 
     */
    public static String DEFAULT_CHARSET = "utf-8";

    /** 
     * Field ipv4
     * Description 
     */
    public static final Pattern ipv4 =
        Pattern.compile("^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$");

    /** 
     * Field targetUrl
     * Description 
     */
    private final String targetUrl;

    /** 
     * Field method
     * Description 
     */
    private String method;

    /** 
     * Field timeout
     * Description 
     */
    private int timeout;

    /** 
     * Field connectionTimeout
     * Description 
     */
    private int connectionTimeout;

    /** 
     * Field parameters
     * Description 
     */
    private Map<String, String> parameters;

    /** 
     * Field charset
     * Description 
     */
    private String charset;

    /** 
     * Field language
     * Description 
     */
    private String language;

    /**
     * Constructs HttpRequest
     * Description
     *
     * @param targetUrl
     */
    public HttpRequest(String targetUrl) {
        this(targetUrl, DEFAULT_CHARSET);
    }

    /**
     * Constructs HttpRequest
     * Description
     *
     * @param targetUrl
     * @param charset
     */
    public HttpRequest(String targetUrl, String charset) {
        this.method            = "POST";
        this.timeout           = 0;
        this.connectionTimeout = 0;
        this.charset           = "utf-8";
        Assert.hasText(targetUrl);
        this.targetUrl = targetUrl;
        charset        = (charset == null) ? DEFAULT_CHARSET : charset;
        Charset.forName(charset);
        this.charset = charset;
    }

    /**
     * Method getParameters
     * Description
     *
     * @return Map<String,String>
     */
    public Map<String, String> getParameters() {
        return this.parameters;
    }

    /**
     * Method setParameters
     * Description
     *
     * @param parameters Map<String,String>
     */
    public void setParameters(Map<String, String> parameters) {
        this.parameters = parameters;
    }

    /**
     * Method getTargetUrl
     * Description
     *
     * @return String
     */
    public String getTargetUrl() {
        return this.targetUrl;
    }

    /**
     * Method getMethod
     * Description
     *
     * @return String
     */
    public String getMethod() {
        return this.method;
    }

    /**
     * Method setMethod
     * Description
     *
     * @param method String
     */
    public void setMethod(String method) {
        this.method = method;
    }

    /**
     * Method getConnectionTimeout
     * Description
     *
     * @return int
     */
    public int getConnectionTimeout() {
        return this.connectionTimeout;
    }

    /**
     * Method setConnectionTimeout
     * Description
     *
     * @param connectionTimeout int
     */
    public void setConnectionTimeout(int connectionTimeout) {
        this.connectionTimeout = connectionTimeout;
    }

    /**
     * Method getTimeout
     * Description
     *
     * @return int
     */
    public int getTimeout() {
        return this.timeout;
    }

    /**
     * Method setTimeout
     * Description
     *
     * @param timeout int
     */
    public void setTimeout(int timeout) {
        this.timeout = timeout;
    }

    /**
     * Method getCharset
     * Description
     *
     * @return String
     */
    public String getCharset() {
        return this.charset;
    }

    /**
     * Method getLanguage
     * Description
     *
     * @return String
     */
    public String getLanguage() {
        return this.language;
    }

    /**
     * Method setLanguage
     * Description
     *
     * @param language String
     */
    public void setLanguage(String language) {
        this.language = language;
    }

    /**
     * Method setCharset
     * Description
     *
     * @param charset String
     */
    public void setCharset(String charset) {
        this.charset = charset;
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
